<?php
//获取环境参数 production 线上  dev测试 kaifa 开发
define('ROOT_PATH', dirname(dirname(__DIR__)));
define('APP_PATH', dirname(__DIR__));
if (empty($_SERVER['APPLICATION_ENV'])) {
    defined('YII_ENV')
    || define('YII_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'dev'));
} else {
    define('YII_ENV', $_SERVER['APPLICATION_ENV']);
}
if (preg_match('/^\/zzcx\/.*$/', $_SERVER['REQUEST_URI']) && empty($_GET['r'])) {
    $url = $_SERVER['REQUEST_URI'];
    $url = parse_url($url);
    $arr = explode('/zzcx', $url['path']);
    $_GET['r'] = $arr[1];
    $_SERVER['SCRIPT_NAME'] = 'wx/admin/web/index.php';
}
if (in_array(YII_ENV,['dev','kaifa','kxpro','production'])) {
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    /**======设置跨域cookies传递===开始=====*/
    header("Access-Control-Allow-Methods: GET,POST");
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-cookies");
    header("Access-Control-Allow-Credentials:true");//如果服务端不设置响应头，响应会被忽略不可用；同时，服务端需指定一个域名（Access-Control-Allow-Origin:www.zawaliang.com），而不能使用泛型（Access-Control-Allow-Origin: *）
    header("Access-Control-Max-Age:60");
    $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
    header('Access-Control-Allow-Origin:'.$origin);
    /**======设置跨域cookies传递===结束=====*/
} else {
    defined('YII_DEBUG') or define('YII_DEBUG', false);
    header("Access-Control-Allow-Origin: *");
}
require(ROOT_PATH . '/vendor/autoload.php');
require(ROOT_PATH . '/vendor/yiisoft/yii2/Yii.php');
require(ROOT_PATH . '/common/config/bootstrap.php');
require(APP_PATH . '/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
    require(ROOT_PATH . '/common/config/main.php'),
    require(ROOT_PATH . '/common/config/appConfig/' . YII_ENV . '/main-local.php'),
    require(APP_PATH . '/config/main.php')
);
$appLiCation = new yii\web\Application($config);
$appLiCation->startTime = microtime(TRUE);//时间差
$appLiCation->defaultRoute = 'base/base/home';
$appLiCation->layout = false;
$appLiCation->run();
